import sys
import pandas as pd

path_prefix=sys.argv[1]
data_df = pd.read_csv(f"{path_prefix}.mdist", sep=" ", header=None)
header_df = pd.read_csv(f"{path_prefix}.mdist.id", sep="\t", header=None)
data_df.dropna(axis=1, how="all", inplace=True)
sample_names = header_df[0].tolist()
data_df.columns = sample_names

for index, row in data_df.iterrows():
    for col in sample_names:
        s = 1 - row[col]
        data_df.at[index, col] = s


data_df.insert(loc=0, column="Code", value=sample_names)

data_df.to_csv(f"{path_prefix}.similarity.csv", index=False)
